package com.ruoyi.project.propertySystem.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.propertySystem.domain.VDocument;
import com.ruoyi.project.propertySystem.service.IVDocumentService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 档案信息Controller
 * 
 * @author wangshuo
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/propertySystem/document")
public class VDocumentController extends BaseController
{
    @Autowired
    private IVDocumentService vDocumentService;

    /**
     * 查询档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(VDocument vDocument)
    {
        startPage();
        List<VDocument> list = vDocumentService.selectVDocumentList(vDocument);
        return getDataTable(list);
    }

    /**
     * 导出档案信息列表
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:document:export')")
    @Log(title = "档案信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(VDocument vDocument)
    {
        List<VDocument> list = vDocumentService.selectVDocumentList(vDocument);
        ExcelUtil<VDocument> util = new ExcelUtil<VDocument>(VDocument.class);
        return util.exportExcel(list, "document");
    }

    /**
     * 获取档案信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(vDocumentService.selectVDocumentById(id));
    }

    /**
     * 新增档案信息
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:document:add')")
    @Log(title = "档案信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VDocument vDocument)
    {
        return toAjax(vDocumentService.insertVDocument(vDocument));
    }

    /**
     * 修改档案信息
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:document:edit')")
    @Log(title = "档案信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VDocument vDocument)
    {
        return toAjax(vDocumentService.updateVDocument(vDocument));
    }

    /**
     * 删除档案信息
     */
    @PreAuthorize("@ss.hasPermi('propertySystem:document:remove')")
    @Log(title = "档案信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vDocumentService.deleteVDocumentByIds(ids));
    }
}
